<?php namespace Admin\Controller;
class TypeController extends CommonController
{
	protected $db;
	public function __init()
	{
		$this->db = new \Common\Model\Type;
	}
	public function index()
	{
		$data = $this->db->get();
	
		View::with("data",$data);
		View::make();
		
	}
	public function add()
	{if(IS_POST)
		{
			if(!$this->db->store()){
				View::error($this->db->getError());
			}else{
				View::success("添加成功",U('index'));
			}
		}
		View::make();
		
	}
	public function edit()
	{
		
		$type_id = Q("get.type_id",0,'intval');
		$oldData = $this->db->where('type_id',$type_id)->first();
		
		//分配数据
		View::with("oldData",$oldData);
		if(IS_POST)
		{
			if(!$this->db->edit())
			{
				View::error($this->db->getError());
			}else
			{
				View::success("编辑成功","index");	
			}			
		}
		View::make();
	}
	public function del()
	{
		
		$type_id = 	Q("get.type_id",0,"intval");
		$data = $this->db->where("type_id",$type_id)->delete();
	
		View::success("删除成功",U('index'));
	}
}
